﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Activities.Validation;
using WFExtended.Activities;
using Microsoft.Activities.UnitTesting;
using WFExtended.Framework.Scheduling;
using System.Activities.Statements.Fakes;
using Microsoft.QualityTools.Testing.Fakes;

namespace WFExtended.Tests.Activities
{
    [TestClass]
    public class CronDelayTest
    {
        public CronDelayTest()
        {

        }

        [TestMethod]
        public void CronDelayWithoutCronExpressionValidationTest()
        {
            ValidationResults result = ActivityValidationServices.Validate(new CronDelay());

            Assert.AreEqual(0, result.Errors.Count);
            Assert.AreEqual(0, result.Warnings.Count);
        }

        [TestMethod]
        public void CronDelayWithCronExpressionValidationTest()
        {
            ValidationResults result = ActivityValidationServices.Validate(new CronDelay()
                {
                    CronExpression = ""
                });

            Assert.AreEqual(0, result.Errors.Count);
            Assert.AreEqual(0, result.Warnings.Count);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void CronDelayWithoutCronExpressionExecutionTest()
        {
            var host = WorkflowInvokerTest.Create(new CronDelay());
            host.TestActivity();

        }

        [TestMethod]
        [ExpectedException(typeof(CrontabException))]
        public void CronDelayWithBadCronExpressionExecutionTest()
        {
            var host = WorkflowInvokerTest.Create(new CronDelay()
                {
                    CronExpression = "badexpression"
                });
            host.TestActivity();

        }

        [TestMethod]
        public void CronDelayWithCronExpressionExecutionTest()
        {
            using (ShimsContext.Create())
            {

                ShimDelay.AllInstances.ExecuteNativeActivityContext = (D, C) =>
                {

                };

                var host = WorkflowInvokerTest.Create(new CronDelay()
                {
                    CronExpression = "2 11 10 1 *"
                });
                host.TestActivity();
            }
        }
    }
}
